package com.ly.aidlpratice.handwritten

import android.os.*
import com.ly.aidlpratice.bean.Book

abstract class ClientBookCallback : Binder(), IBookCallback {

    @Throws(RemoteException::class)
    override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean {
        when (code) {
            INTERFACE_TRANSACTION -> {
                reply?.writeString(BOOK_CALLBACK_TOKEN)
                return true
            }
            TRANSACTION_CALLBACK -> {
                data.enforceInterface(BOOK_CALLBACK_TOKEN)
                val book = Book.CREATOR.createFromParcel(data)
                callback(book)
                return true
            }
        }
        return super.onTransact(code, data, reply, flags)
    }

    override fun asBinder(): IBinder {
        return this
    }
}